import java.util.Deque;
import java.util.LinkedList;
import java.util.Queue;

public class Test {
        public Queue<Integer> qu1;
        public Queue<Integer> qu2;
        public Test() {
            qu1=new LinkedList<>();
            qu2=new LinkedList<>();
        }

        public void push(int x) {
            if(!qu1.isEmpty()){
                qu1.offer(x);
            }
            else if(!qu2.isEmpty()){
                qu2.offer(x);
            }else{
                qu1.offer(x);
            }
        }

        public int pop() {
            if(empty()){
                return-1;
            }
            if(!qu1.isEmpty()){
                int size=qu1.size();
                while(size-1!=0){
                    int val=qu1.poll();
                    qu2.offer(val);
                    size--;
                }
                return qu1.poll();
            }
            else{
                int size=qu2.size();
                while(size-1!=0){
                    int val=qu2.poll();
                    qu1.offer(val);
                    size--;
                }
                return qu2.poll();
            }
        }


        public int top() {
            if(empty()){
                return-1;
            }
            if(!qu1.isEmpty()){
                int size=qu1.size();
                int val=-1;
                while(size!=0){
                    val=qu1.poll();
                    qu2.offer(val);
                    size--;
                }
                return val;
            }
            else{
                int size=qu2.size();
                int val=-1;
                while(size!=0){
                    val=qu2.poll();
                    qu1.offer(val);
                    size--;
                }
                return val;
            }
        }


        public boolean empty() {
            return qu1.isEmpty()&&qu2.isEmpty();
        }
    class MyQueue {
        public Deque<Integer> s1;
        public Deque<Integer> s2;
        public MyQueue() {
            s1=new LinkedList<>();
            s2=new LinkedList<>();
        }

        public void push(int x) {
            s1.push(x);
        }

        public int pop() {
            if(empty()){
                return -1;
            }
            if(s2.isEmpty()){

                while(!s1.isEmpty()){
                    int  val=s1.pop();
                    s2.push(val);
                }
            }
            return s2.pop();
        }

        public int peek() {
            if(empty()){
                return -1;
            }

            if(s2.isEmpty()){
                while(!s1.isEmpty()){
                    int  val=s1.pop();
                    s2.push(val);
                }
            }
            return s2.peek();
        }

        public boolean empty() {
            return s2.isEmpty()&&s1.isEmpty();
        }
    }


    }



